package com.moneywelcome.exceptionHandler;

import com.moneywelcome.exceptions.BaseException;
import com.moneywelcome.results.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e){
        log.error("全局异常：{}",e);
        return Result.fail("SERVER_EXCEPTION","服务器异常");
    }

    @ExceptionHandler(BaseException.class)
    public Result handleBaseException(BaseException e){
        log.error("出现异常：{}",e);
        return Result.fail(e.getCode(),e.getMessage());
    }

}
